home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 3.4 KB | 151 lines | [TEXT/GEOL] |
- Item 2613680 18-Jan-90 02:08
-
- From: CDA0004 VAR Shana Corp, Don Murphy
-
- To: AUST0134 Jam Software Sydney
- MACAPP.TECH$ MacApp Technical
-
- Sub: R» ISO Failures (long)
-
- Attn: Tseung Cheung
- Attn: MacApp Technical
- SentBy: Wayne Malkin
- Date 1/17/90
- Subject R» ISO Failures (long)
- From Wayne Malkin
- To Tseung Cheung
- MacApp Technical
-
- Memo Subject:R» ISO Failures (long)
- Tseung,
-
- Your error handling scheme looks all right (from an Inside Out perspective),
- except for one point. All though I haven't tried it, I suspect that calling
- Failure to drop out of an Inside Out error handler is VERY NASTY!
-
- If you call Failure from within the Inside Out error handler, you are EXIT'ing
- everything out to your nearest MacApp failure handler, which bypasses all the
- pending code in Inside Out. This leaves Inside Out globals in an inconsistent
- state, which bodes ill for any future calls to Inside Out.
-
- Generally I would say don't cause a MacApp failure directly out of an Inside
- Out error handler. Instead, write a little routine to signal a MacApp failure
- after the Inside Out call returns. You can write one which fails on any Inside
- Out error, and one which traps unexpected errors which you can filter in a
- local error handler.
-
-
- VAR
- gISOErr : Integer; { Initialize to 0 somewhere }
-
-
- PROCEDURE FailUnexpected;
- { Fails if an unexpected Inside Out error is not trapped in a local
- error handler. }
- BEGIN
- IF gISOErr <> noErr THEN
- Failure (gISOErr);
- END;
-
-
- PROCEDURE FailInsideOut;
- { Fails on any Inside Out error }
- VAR
- err : Integer;
- BEGIN
- err := DBError;
- IF err <> noErr THEN
- Failure (err,0);
- END;
-
-
- So your global Inside Out error handler looks like this:
-
-
- FUNCTION MyDBErrorHandler (errCode : Integer; procName : tName) : Boolean;
- VAR
- aBool : Boolean;
- BEGIN
- { Display the error (I assume for debugging purposes) }
- aBool := DBErrorHandler (errCode,procName);
-
- { Save it in a global for FailUnexpected }
- gISOErr := errCode;
- END;
-
-
-
- And, in a complex procedure:
-
-
- PROCEDURE TreadCarefully;
- VAR
- pop : Boolean;
- fi : FailInfo;
-
-
- PROCEDURE FailureHandler (error : OSErr; message : LongInt);
- BEGIN
- IF pop THEN
- DBPopError;
- { clean up }
- END;
-
-
- FUNCTION ISOErrorHandler (errCode : Integer; procName : tName) : Boolean;
- BEGIN
- ISOErrorHandler := FALSE;
- IF { errcode is something I expect } THEN
- BEGIN
- { Handle the error }
- ISOErrorHandler := TRUE;
- END;
- END;
-
-
- BEGIN
- pop := FALSE;
- CatchFailures (fi,FailureHandler);
-
- 1:
- { Things which can fail }
-
- 2:
- { Inside Out calls which should fail }
- SRInsert (theVw,@theRec);
- FailInsideOut;
-
- 3:
- { Inside Out calls which should be trapped locally }
- DBPushError (@ISOErrorHandler,@pop);
- pop := TRUE;
- IF SRNext (………) THEN
- BEGIN
- END;
- FailUnexpected;
-
- 4:
- { Other things }
- DBPopError;
- pop := FALSE;
-
- Success (fi);
- END;
-
-
- Note that the Inside Out error handlers are NEVER popped unless you explicitly
- pop them, unlike the failure handlers in MacApp.
-
- I hope this covers most of the cases you are trying to handle. Remember: don't
- fail from within an Inside Out error handler. You have to find some way to
- save the error, return to Inside Out, and fail just after the Inside Out call
- returns.
-
- Regards,
-
- Wayne Malkin
- Project Manager / Inside Out
- Shana Corporation
-
-
-